package controller;

import Dao.QuestionDao;
import entity.Question;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "QuestionAddServlet")
public class QuestionAddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String title = request.getParameter("title");
        String optionA = request.getParameter("optionA");
        String optionB = request.getParameter("optionB");
        String optionC = request.getParameter("optionC");
        String optionD = request.getParameter("optionD");
        String answer = request.getParameter("answer");
        Question question = new Question(null, title, optionA, optionB, optionC, optionD, answer);
        QuestionDao dao = new QuestionDao();
        int result = dao.add(question, request);
        request.setAttribute("addResult", result);
        request.getRequestDispatcher("/question_Add.jsp").forward(request, response);
    }
}
